def simpcheck(a):
    count = 0
    nod = a
    while nod != 0:
        if a % nod == 0:
            count += 1
        nod -= 1
    return(count)
N = int(input())
simplenumbers = []
if len(str(N)) == 4:
    ns = N

    while ns != 0:
        if simpcheck(ns) == 2:
            simplenumbers += [ns]
        ns //= 10

    ns = N
    d = 1000

    while ns != 0:
        if simpcheck(ns) == 2:
            simplenumbers += [ns]
        ns %= d
        d //= 10
    if simplenumbers == []:
        print(0)
    else:
        print(max(simplenumbers))
else:
    print(0)
